//
//  AchievedGoalPopupView.swift
//  DaRings
//
//  Created by 魔样科技 on 2022/12/16.
//

/* Use Example
 private lazy var goalArchievedView: AchievedGoalPopupView = {
     let view = AchievedGoalPopupView()
     view.type = .trainingGoal
     view.iconImageView.image = UIImage(named: "ic_achieved_goal_gpsTraining")
     view.titleLabel.text = "Good job"
     let attributeString = "45".toAttributed
         .foregroundColor(.Sleep.assist_FFC634)
         .font(Fonts.boldSystemFont(ofSize: 20))
         .rawValue
     attributeString.append("unit_minute".language
         .toAttributed.foregroundColor(.assist_A9A9A9)
         .font(Fonts.systemFont(ofSize: 14))
         .rawValue
     )
     attributeString.append("goal achieved!\nKeep it up!".language
         .toAttributed.foregroundColor(.assist_A9A9A9)
         .font(Fonts.systemFont(ofSize: 14))
         .rawValue
     )
     view.subtitleLabel.attributedText = attributeString
     return view
 }()
 
 */

import Foundation
import MYModule
import UIKit

public enum GoalType {
    case trainingGoal
    case singleGoal
    case highHeartRate
    case lowBattery
    case sedentaryReminder
}

open class AchievedGoalPopupView: View {
    
   public var type: GoalType = .singleGoal {
        didSet {
            self.switchUI()
        }
    }
    
    open override func makeUI() {
        super.makeUI()
        
        self.addSubview(self.okButton)
        self.okButton.snp.makeConstraints { make in
            make.bottom.equalTo(-26)
            make.centerX.equalToSuperview()
            make.left.equalTo(62)
            make.height.equalTo(48)
            make.width.equalTo(170)
        }
        
    
        self.addSubview(self.subtitleLabel)
        self.subtitleLabel.snp.makeConstraints { make in
            make.bottom.equalTo(self.okButton.snp.top).offset(-10)
            make.centerX.equalToSuperview()
            make.left.equalTo(20)
        }
        
        self.addSubview(self.titleLabel)
        self.titleLabel.snp.makeConstraints { make in
            make.bottom.equalTo(self.subtitleLabel.snp.top).offset(-4)
            make.centerX.equalToSuperview()
            make.left.equalTo(20)
        }
        
        self.addSubview(self.iconImageView)
        self.iconImageView.snp.makeConstraints { make in
            make.bottom.equalTo(self.titleLabel.snp.top)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(20)
        }
        
        self.setupDefaultData()
    }
    
    private func setupDefaultData() {
        self.backgroundColor = .white
        self.cornerRadius = 20
    }
    
    
    private func switchUI() {
        switch self.type {
        case .highHeartRate:
            self.iconImageView.snp.remakeConstraints { make in
                make.bottom.equalTo(self.titleLabel.snp.top).offset(-58)
                make.centerX.equalToSuperview()
                make.top.equalTo(80)
            }
        case .trainingGoal:
            break
            
        case .singleGoal:
            self.subtitleLabel.snp.makeConstraints { make in
                make.height.equalTo(0)
            }
            break
        case .lowBattery:
            self.iconImageView.snp.remakeConstraints { make in
                make.bottom.equalTo(self.titleLabel.snp.top).offset(-20)
                make.centerX.equalToSuperview()
                make.top.equalTo(58)
            }
        case .sedentaryReminder:
            self.iconImageView.snp.remakeConstraints { make in
                make.bottom.equalTo(self.titleLabel.snp.top).offset(-16)
                make.centerX.equalToSuperview()
                make.top.equalTo(0)
            }
        }
    }
    
    //MARK: - lazy load -
    
    public lazy var iconImageView: ImageView = {
        let imageView = ImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    
    public lazy var titleLabel: Label = {
        let label = Label()
        label.font = Fonts.boldSystemFont(ofSize: 20)
        label.textColor = UIColor.init(hex: "261A00")
        label.textAlignment = .center
        label.numberOfLines = 0
        return label
    }()
    
    public lazy var subtitleLabel: Label = {
        let label = Label()
        label.font = Fonts.boldSystemFont(ofSize: 14)
        label.textColor = UIColor.assist_A9A9A9
        label.textAlignment = .center
        label.numberOfLines = 0
        return label
    }()
    
    public lazy var okButton: Button = {
        let button = Button()
        button.setTitle("dialog_ok".language, for: .normal)
        button.setTitleColor(UIColor.assist_FFFFFF, for: .normal)
        button.backgroundColor = UIColor.GPSTraining.theme
        
        button.layer.cornerRadius = 24
        button.layer.shadowColor = UIColor.init(hex: "006446").cgColor
        button.layer.shadowRadius = 12
        button.layer.shadowOffset = CGSize(width: 0, height: 8)
        button.layer.shadowOpacity = 0.25
        
        return button
    }()

}
